﻿using System;
using System.Data.Common;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Pub.Class;
using GTS.MiniBox.Helper;
using GTS.MiniBox.Entity;
using System.Web;

namespace GTS.MiniBox.Page {
    /// <summary>
    /// 下载gbx
    /// </summary>
    public class Download : System.Web.UI.Page {
        /// <summary>
        /// Page_Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e) {
            HttpContext.Current.Response.ContentType = "application/octet-stream";
            HttpContext.Current.Response.AddHeader("SPECIAL", "GTSBOX");

            string originID = Request2.Get("originid");
            string gameID = Request2.Get("appid");
            if (originID.IsNullEmpty() || gameID.IsNullEmpty()) return;

            DataSet ds = Data.Pool("BoxMTK").GetDataSet("DownLoadGameProc '{0}','{1}'".FormatWith(originID.SafeSql(), gameID.SafeSql()));
            if (ds.Tables.Count == 1) {
                DataTable dt = ds.Tables[0];
                if (dt.Rows.Count > 0) {
                    if (dt.Rows[0][0] != null && dt.Rows[0][1] != null)
                        SiteConfig.ResponseGameInfo(HttpContext.Current.Request, HttpContext.Current.Response, dt.Rows[0][0].ToString(), (Byte[])dt.Rows[0][1]);
                }
            }
        }
    }
}
